package com.why.blog.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.why.blog.bean.Blog;
import com.why.blog.service.BlogService;
import com.why.blog.service.typeService;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: blog
 * @description:
 * @author: @why
 * @create: 2021-01-16 11:41
 **/
@Slf4j
@Controller
public class BlogController {

    @Autowired
    private BlogService blog;
    @Autowired
    private typeService type;

    private final Integer  PageNums=3;

    /**
     *
     * @param model
     * @param pageNo
     * @return
     */
    @GetMapping(value = {"/","index"})
    public String indexController(Model model,
                                  @RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNo){

        pageNo=pageNo==0?1:pageNo;
       // System.out.println(pageNo);
        PageHelper.startPage(pageNo,6);
        PageInfo<Blog> blogInfo = new PageInfo<Blog>(blog.getListBlogNoContent());
        model.addAttribute("msg", blogInfo);
        model.addAttribute("types",type.getListType());
       // System.out.println(type.getListType().size());
        //log.error(String.valueOf(blogInfo.getList().size()));
        return "index";
    }






}
